package cn.itsource.web.controller;

import cn.itsource.domain.CourseDoc;
import cn.itsource.dto.CourseDocQuery;
import cn.itsource.repository.CourseDocElasticsearchRepository;
import cn.itsource.service.CourseDocQueryService;
import cn.itsource.ymcc.result.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/search")
public class EsController {
    @Autowired
    private CourseDocElasticsearchRepository repository;
    @Autowired
    private CourseDocQueryService courseDocQueryService;

    /**
     * 课程修改之后得数据存放到ES中
     * @param docList  课程的全部数据
     * @return
     */
    @PostMapping("/batchSave")
    public JsonResult batchSave(@RequestBody List<CourseDoc> docList) {
        repository.saveAll(docList);
        return JsonResult.success();
    }

    @PostMapping("/queryCourse")
    public JsonResult queryCourse(@RequestBody CourseDocQuery courseDocQuery) {
        return courseDocQueryService.queryCourse(courseDocQuery);
    }
}

